/**
 * (created at 2011-1-29)
 */
package qiushuo.mysqlparser.ast.statement;

import java.util.List;

import qiushuo.mysqlparser.ast.expression.Expression;
import qiushuo.mysqlparser.ast.fragment.Limit;
import qiushuo.mysqlparser.ast.fragment.OrderBy;

/**
 * @author <a href="mailto:QiuShuo1985@gmail.com">QIU Shuo</a>
 */
public class DMLSelectUnionStatement extends DMLStatement implements Expression {
    private final List<DMLSelectStatement> selectStmtList;
    private final boolean unionAll;
    private final OrderBy orderBy;
    private final Limit limit;

    @SuppressWarnings("unchecked")
    public DMLSelectUnionStatement(List<DMLSelectStatement> selectStmtList, boolean unionAll, OrderBy orderBy,
                                   Limit limit) {
        this.selectStmtList = ensureListType(selectStmtList);
        this.unionAll = (this.selectStmtList != null && this.selectStmtList.size() > 1) ? unionAll : false;
        this.orderBy = orderBy;
        this.limit = limit;
    }

    @Override
    public int getPrecedence() {
        return PRECEDENCE_PRIMARY;
    }

}
